package com.xsq.audio.player.utils;

/**
 * Created by Shiquan.Xiao on 2023/4/3.
 */
public class FormatUtil {

    /**
     * 格式化时间
     *
     * @param time 时间值 (00:00 -23:59:59)
     * @return 时间
     */
    public static String formatTime(long time) {
        long temp = time;
        if (temp == 0L) {
            return "00:00";
        }
        temp /= 1000;
        long s = (temp % 60); // s秒
        long m = (temp / 60 % 60); //m分
        long h = (temp / 60 / 60 % 24); //h小时s

        if (h > 0) {
            return strNumber(h) +":" + strNumber(m) +":"+ strNumber(s);
        } else {
            return strNumber(m) +":"+ strNumber(s);
        }
    }

    private static String strNumber(long number) {
        if (number > 9) {
            return number+"";
        } else {
            return "0"+number;
        }
    }

}
